import json

import pytest

from API.course import CourseAPI
from API.login import LoginAPI

class TestAddCourse:
    uuid=None
    token=None
    def setup_method(self):
        # 实例化
        self.login_api=LoginAPI()
        self.course_api=CourseAPI()
        res_v=self.login_api.get_verify_code()
        TestAddCourse.uuid=res_v.json()["uuid"]
        test_data = {

            "username": "admin",
            "password":"HM_2023_test",
            "code": "2",
            "uuid": TestAddCourse.uuid
        }
        res_login_success = self.login_api.login(test_data=test_data)
        print(res_login_success.json())
        TestAddCourse.token=res_login_success.json()["token"]
    def teardown(self):
        pass
    # 1、课程id存在
    def test01_delete_course(self):
        res_add_course = self.course_api.delete_course(id=23056458704374122, token=TestAddCourse.token)
        # print(res_add_course.json())
        assert res_add_course.status_code==200
        assert "成功" in res_add_course.text
        assert 200==res_add_course.json()["code"]
    # 2课程id不存在
    def test02_delete_course(self):
        res_add_course = self.course_api.delete_course(id=6666, token=TestAddCourse.token)
        # print(res_add_course.json())
        assert res_add_course.status_code == 200
        assert "失败" in res_add_course.text
        assert 500 == res_add_course.json()["code"]
        # 3未登录
    def test03_delete_course(self):
        res_add_course = self.course_api.delete_course(id=23056458704374122, token="")
        assert res_add_course.status_code==200
        assert "失败" in res_add_course.text
        assert 401==res_add_course.json()["code"]

